<?php

class LoanMasters extends HTech_Db_Table
{
    protected $_name    = 'view_loan_masters';
    protected $_primary = 'LoanMasterId';  
    
    protected $_dependentTables = array('Loans'); 
    
    protected function _setGridMetadata()
    {
        $this->_gridMetadata['title'] = $this->translate("Loan masters");
        $this->_gridMetadata['titleMods'] = array('Status','LocationShortName','OfficerUsername','Program','ProductLine');
        $this->_gridMetadata['params'] = array('ProductLineId','ProgramId','OfficerUserId','LocationId','LocationShortName','OfficerUsername','Status');
        $this->_gridMetadata['onClick'] = 'loan.loan-master.view';
        $this->_gridMetadata['headers'] = array
            (
                array('LoanMasterId',          100, $this->translate("Id"),           'Number'),
                array('Status',                100, $this->translate("Check status"), 'String'),
                array('CheckNumber',           100, $this->translate("Check no."),    'Number'),
                array('Amount',                100, $this->translate("Amount"),       'Number',   'Standard'),
                array('LocationShortName',     100, $this->translate("Branch"),       'String'),
                array('OfficerUsername',       120, $this->translate("Officer"),      'String'),
                array('ProductLineName',       250, $this->translate("Line"),         'String'),
                array('ProgramName',           200, $this->translate("Program"),      'String'),
                array('TentativeDeliveryDate', 150, $this->translate("Deli. date"),   'DateTime', 'Date'),
                array('Borrower',              450, $this->translate("Borrower"),     'String')
            );
        return $this;
    }
    
    protected function _setRecordDependentRows()
    {
        $this->_record->r = (object) array('loans' => null);
        $this->_record->r->loans = $this->_record->d->findDependentRowset('Loans');      
    }
    
    /*
    public function updateAmount($id)
    {
        $sql = sprintf("
            update 
                loan_masters lm 
            set 
                lm.Amount = (select sum(l.Principal) Amount from loans l where l.LoanMasterId = %s) 
            where 
                lm.LoanMasterId = %s", $id, $id);
        Zend_Registry::get('db')->query($sql);      
    }
     * 
     */
}